Fragmentation of files due to host fragmentation or storage module fragmentation can degrade system performance. With host fragmentation, files are scattered across many non-consecutive logical block address (LBA) ranges of the storage module. So, the more LBA ranges are used to store a file, the more fragmented the file becomes. Further, in some file systems, such as EXT4, the file allocation table (FAT) is mixed with stored data. Reading a fragmented file in such a system requires more operations, as the structure of the file is more complicated. This can degrade read performance.
With storage module fragmentation, files are scattered among many physical blocks in memory. The more physical blocks that are allocated for the same file, the more fragmented the file is. Because a fragmented file often does not occupy the entire physical block, a physical block that stores part of a fragmented file will often store data of other files. So, when a host deletes a file that is fragmented over several physical blocks, this may result in fewer free blocks than intended, as the blocks still hold data for other files. Because such a file deletion will leave “holes” of free space in an otherwise-occupied physical block, the storage module will need to perform several “housekeeping” operations to create a free block, which can degrade system performance.
Additionally, in some environments, such as in mobile computing systems, when a file is fragmented by the storage module, the host does not know how fragmented the file is, so it does not know what action is needed to attempt to defragment the file. Further, while a host is aware of the host-fragmentation problem and can attempt to solve it by moving a scattered file to consecutive LBA ranges, such moving can actually degrade performance because of the storage fragmentation problem.
Overview
Embodiments of the present invention are defined by the claims, and nothing in this section should be taken as a limitation on those claims.
By way of introduction, various embodiments relate to a storage module and host device for storage module defragmentation. In one embodiment, a host controller sends a storage module a first set of logical block addresses of a file stored in the storage module. The host controller receives a metric from the storage module indicative of a fragmentation level of the file in physicals blocks of memory in the storage module. If the metric is greater than a threshold, the host controller reads the file and then writes it back to the storage module using a different set of logical block addresses. To avoid sending the file back and forth, in another embodiment, the host controller sends the fragmentation threshold and the different set of logical block addresses to the storage module. The storage module then moves the file itself if the metric indicative of the fragmentation level is greater than the threshold. To perform this embodiment on a plurality of files, the host controller can send the information about the files on a file-by-file basis to the storage module or can send the information as a group to the storage module. In another embodiment, a host controller sends, to the storage module, a set of logical block addresses of a file stored in the storage module, and the storage module generates, and sends to the host controller, a metric indicative of a level of fragmentation level of the file in physical blocks of memory in the storage module. In yet another embodiment, a host controller reads a file stored in a storage module and writes it back to the storage module according to a specified writing mode.
Other embodiments are possible, and each of the embodiments can be used alone or together in combination. Accordingly, various embodiments will now be described with reference to the attached drawings.